﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls.Primitives;
using System.Windows;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.IO;
using System.Windows.Markup;
using System.Security.Principal;
using System.Windows.Resources;
using System.Collections;
using System.Windows.Controls;
using System.Data;
using System.ComponentModel;
using CMD.BAL.CAT;
using CMD.BAL.MISC;
using System.Text.RegularExpressions;
using System.Reflection;
using CMD_DKT.BAL;
using CMD_DKT.Utilities;

namespace CMD_DKT.Sol
{
    class UIReemplazos : UINuevaSolicitud
    {
        public TextBox txt_numeroCliente;
        public TextBox txt_nombreCliente;
        public UIReemplazos(ContentControl PA, ContentControl PN, ScrollViewer PC)
            : base(PA, PN, PC)
        {
            PanelAccion = PA;
            PanelNavegacion = PN;
            PanelCentral = PC;
            PanelAccion.Content = null;
            this.liTxt = new List<TextBox>();
            MainWindow mw = (MainWindow)App.Current.MainWindow;
            lbl_Saving = mw.lbl_Saving;

            #region Cagar Panel de Acción después de accionar ALTA

            string nombre = @"BotonesAlta.xaml";

            DependencyObject rootElement;
            using (FileStream fs = new FileStream(nombre, FileMode.Open))
            {
                rootElement = (DependencyObject)XamlReader.Load(fs);
            }

            PanelAccion.Content = rootElement;
            FrameworkElement frameworkElement = (FrameworkElement)rootElement;

            lblEnviar = (Image)frameworkElement.FindName("img_Enviar");
            lblEnviar.MouseUp += new MouseButtonEventHandler(lblEnviar_MouseUp);
            lblEnviar.PreviewMouseUp += new MouseButtonEventHandler(lblEnviar_PreviewMouseDown);

            lblGuardar = (Image)frameworkElement.FindName("img_Guardar");
            lblGuardar.MouseUp += new MouseButtonEventHandler(lblGuardar_MouseUp);
            lblGuardar.PreviewMouseUp += new MouseButtonEventHandler(lblGuardar_PreviewMouseUp);


            Image bdCancelar = (Image)frameworkElement.FindName("img_Cancelar");
            bdCancelar.MouseUp += new MouseButtonEventHandler(bdCancelar_MouseUp);

            popArchivos = (Popup)frameworkElement.FindName("popArchivo");
            spArchivos = (StackPanel)frameworkElement.FindName("spArchivos");
            bdArchivos = (Image)frameworkElement.FindName("img_Archivos");
            bdArchivos.MouseUp += new MouseButtonEventHandler(bdArchivos_MouseUp);

            popPrioridad = (Popup)frameworkElement.FindName("popPrioridad");
            spPrioridades = (StackPanel)frameworkElement.FindName("spPrioridades");
            bdPrioridad = (Image)frameworkElement.FindName("img_Prioridad");
            bdPrioridad.MouseUp += new MouseButtonEventHandler(bdPrioridad_MouseUp);
            cargarPrioridades();

            //lblGuardarYSalir
            lblGuardarYSalir = (Image)frameworkElement.FindName("img_GuardarYSalir");
            lblGuardarYSalir.MouseUp += new MouseButtonEventHandler(lblGuardar_MouseUp);
            lblGuardarYSalir.PreviewMouseUp += new MouseButtonEventHandler(lblGuardar_PreviewMouseUp);

            Image lblInfoDoc = (Image)frameworkElement.FindName("img_InfoDoc");
            lblInfoDoc.MouseUp += new MouseButtonEventHandler(lblInfoDoc_MouseUp);
            txtBlockStatus = (TextBlock)frameworkElement.FindName("txtBlock_Status");
            #endregion
            #region Buscar elementos de Reemplazos

            string nombrens = @"Reemplazos.xaml";
            DependencyObject rootElementns;
            using (FileStream fsns = new FileStream(nombrens, FileMode.Open))
            {
                rootElementns = (DependencyObject)XamlReader.Load(fsns);
            }

            PanelCentral.Content = rootElementns;
            FrameworkElement frameworkElementns = (FrameworkElement)rootElementns;
            this.feNs = frameworkElementns;

            spAlta = (StackPanel)frameworkElementns.FindName("spReemplazo");
            lbl_unidSol = (Label)frameworkElementns.FindName("lbl_unidSol");
            lbl_unidDatgral = (Label)frameworkElementns.FindName("lbl_unidDatgral");
            lbl_unidDirFiscal = (Label)frameworkElementns.FindName("lbl_unidDirFiscal");
            lbl_unidDirEntrega = (Label)frameworkElementns.FindName("lbl_unidDirEntrega");
            lbl_unidRFV = (Label)frameworkElementns.FindName("lbl_unidRFV");
            lbl_unidDPV = (Label)frameworkElementns.FindName("lbl_unidDPV");
            lbl_unidInfoad = (Label)frameworkElementns.FindName("lbl_unidInfoad");
            lbl_unidBanc = (Label)frameworkElementns.FindName("lbl_unidBanc");
            lbl_unidDocinfo = (Label)frameworkElementns.FindName("lbl_unidDocinfo");
            lbl_unidInterlocutores = (Label)frameworkElementns.FindName("lbl_unidInterlocutores");
            lbl_unidWf = (Label)frameworkElementns.FindName("lbl_unidWf");
            lbl_unidDocumentos = (Label)frameworkElementns.FindName("lbl_unidDocumentos");
            lbl_unidDatos = (Label)frameworkElementns.FindName("lbl_unidDatos");
            lbl_idPrioridad = (Label)frameworkElementns.FindName("lbl_idPrioridad");
            lbl_idStatus = (Label)frameworkElementns.FindName("lbl_idStatus");

            txt_numeroCliente = (TextBox)frameworkElementns.FindName("tbNoCliente");
            txt_numeroCliente.MaxLength = (System.Convert.ToInt32(((DataTable)TableLength.GetData("CMD_SOLICITUD", "NUMERO_CLIENTE")).Rows[0]["LARGO"].ToString()));
            txt_nombreCliente = (TextBox)frameworkElementns.FindName("tbNomCliente");
            txt_nombreCliente.MaxLength = (System.Convert.ToInt32(((DataTable)TableLength.GetData("CMD_SOLICITUD", "NOMBRE_CLIENTE")).Rows[0]["LARGO"].ToString()));
            lbl_idTipo = (Label)frameworkElementns.FindName("lbl_idTipo");
            txt_nombreCliente.LostFocus += new RoutedEventHandler(txt_nombreCliente_LostFocus);
            txt_numeroCliente.LostFocus += new RoutedEventHandler(txt_numeroCliente_LostFocus);
            lbl_idTipo.Content = "3";
            lbl_idPrioridad.Content = "3";
            #region Controles de la sección de Nueva Solicitud
            lbTipoSolicitud = (Label)frameworkElementns.FindName("lblTipoSolicitud");
            lbTipoSolicitud.Content = "Reemplazo";
            gdDirEntrega = (Grid)frameworkElementns.FindName("gdDirEntrega");
            cTipoSolicitud = (ComboBox)frameworkElementns.FindName("cbTipoSolicitud");
            cTipoSolicitud.SelectionChanged += new SelectionChangedEventHandler(cTipoSolicitud_SelectionChanged);
            chProveedor = (CheckBox)frameworkElementns.FindName("chbProveedor");
            chMismoDom = (CheckBox)frameworkElementns.FindName("chbMismoDom");
            chOtrosClientes = (CheckBox)frameworkElementns.FindName("chbOtrosClientes");
            cPersona = (ComboBox)frameworkElementns.FindName("cbPersona");
            cPersona.SelectionChanged += new SelectionChangedEventHandler(cPersona_SelectionChanged);
            chOtrasCateg = (CheckBox)frameworkElementns.FindName("chbOtrasCateg");

            chMismoDom.Click += new RoutedEventHandler(chMismoDom_Click);
            chOtrosClientes.Click += new RoutedEventHandler(chOtrosClientes_Click);
            #endregion  
           #region Controles de la sección Datos Generales
            cTipoNegocios = (ComboBox)frameworkElementns.FindName("cbTipoNegocios");
            tRazonSocial = (TextBox)frameworkElementns.FindName("tbRazonSocial");
            tRazonSocial.MaxLength = (System.Convert.ToInt32(((DataTable)TableLength.GetData("CMD_SOLICITUD_DATOSGRAL", "RAZON_SOCIAL")).Rows[0]["LARGO"].ToString()));
            tRazonSocial.LostFocus +=new RoutedEventHandler(tRazonSocial_LostFocus);
            cGrupoClientes4 = (ComboBox)frameworkElementns.FindName("cbGrupoClientes4");
            tRFC = (TextBox)frameworkElementns.FindName("tbRFC");
            tRFC.MaxLength = (System.Convert.ToInt32(((DataTable)TableLength.GetData("CMD_SOLICITUD_DATOSGRAL", "RFC")).Rows[0]["LARGO"].ToString()));
            tRFC.LostFocus += new RoutedEventHandler(tRFC_LostFocus);
            tEmail = (TextBox)frameworkElementns.FindName("tbEmail");
            tEmail.MaxLength = (System.Convert.ToInt32(((DataTable)TableLength.GetData("CMD_SOLICITUD_DATOSGRAL", "CORREO")).Rows[0]["LARGO"].ToString()));
            tNumeroSucursal = (TextBox)frameworkElementns.FindName("tbNumeroSucursal");
            tNumeroSucursal.MaxLength = (System.Convert.ToInt32(((DataTable)TableLength.GetData("CMD_SOLICITUD_DATOSGRAL", "NUMERO_SUCURSAL")).Rows[0]["LARGO"].ToString()));
            tNombreSucursal = (TextBox)frameworkElementns.FindName("tbNombreSucursal");
            tNombreSucursal.MaxLength = (System.Convert.ToInt32(((DataTable)TableLength.GetData("CMD_SOLICITUD_DATOSGRAL", "NOMBRE_SUCURSAL")).Rows[0]["LARGO"].ToString()));
            tEmail.LostFocus += new RoutedEventHandler(Email_LostFocus);
            tNombreSucursal.LostFocus += new RoutedEventHandler(tNombreSucursal_LostFocus);
            tNumeroSucursal.LostFocus += new RoutedEventHandler(tNumeroSucursal_LostFocus);

            #endregion

            #region Controles de la sección Dirección Fiscal
            tCalle = (TextBox)frameworkElementns.FindName("tbCalle");
            tCalle.MaxLength = (System.Convert.ToInt32(((DataTable)TableLength.GetData("CMD_SOLICITUD_DIRFISCAL", "CALLE")).Rows[0]["LARGO"].ToString()));
            tCalle.LostFocus +=new RoutedEventHandler(tCalle_LostFocus);
            tNoExterior = (TextBox)frameworkElementns.FindName("tbNoExterior");
            tNoExterior.MaxLength = (System.Convert.ToInt32(((DataTable)TableLength.GetData("CMD_SOLICITUD_DIRFISCAL", "NUMERO_EXTERIOR")).Rows[0]["LARGO"].ToString()));
            tNoExterior.LostFocus +=new RoutedEventHandler(tNoExterior_LostFocus);
            tNoInterior = (TextBox)frameworkElementns.FindName("tbNoInterior");
            tNoInterior.MaxLength = (System.Convert.ToInt32(((DataTable)TableLength.GetData("CMD_SOLICITUD_DIRFISCAL", "NUMERO_INTERIOR")).Rows[0]["LARGO"].ToString()));
            tNoInterior.LostFocus+=new RoutedEventHandler(tNoInterior_LostFocus);
            tCodigoPostal = (TextBox)frameworkElementns.FindName("tbCodigoPostal");   
            tDelMunicipio = (TextBox)frameworkElementns.FindName("tbDelMunicipio");
            cColoniaDistrito = (ComboBox)frameworkElementns.FindName("cbColoniaDistrito");
            cLocalidad = (ComboBox)frameworkElementns.FindName("cbLocalidad");
            tEstado = (TextBox)frameworkElementns.FindName("tbEstado");
            
            tLada = (TextBox)frameworkElementns.FindName("tbLada");
            tLada.MaxLength = (System.Convert.ToInt32(((DataTable)TableLength.GetData("CMD_SOLICITUD_DIRFISCAL", "LADA")).Rows[0]["LARGO"].ToString()));
            tLada.LostFocus+=new RoutedEventHandler(tLada_LostFocus);
            tTelFiscal = (TextBox)frameworkElementns.FindName("tbTelFiscal");
            tTelFiscal.MaxLength = (System.Convert.ToInt32(((DataTable)TableLength.GetData("CMD_SOLICITUD_DIRFISCAL", "TELEFONO")).Rows[0]["LARGO"].ToString()));
            tEstado.IsEnabled = false;
            tDelMunicipio.IsEnabled = false;

            tbTelExtFiscal = (TextBox)frameworkElementns.FindName("tbTelExtFiscal");
            tbFaxFiscal = (TextBox)frameworkElementns.FindName("tbFaxFiscal");
            tbFaxExtFiscal = (TextBox)frameworkElementns.FindName("tbFaxExtFiscal");


            tCalle.TextChanged += new TextChangedEventHandler(tCalle_TextChanged);
            tNoExterior.TextChanged += new TextChangedEventHandler(tNoExterior_TextChanged);
            tNoInterior.TextChanged += new TextChangedEventHandler(tNoInterior_TextChanged);
            tCodigoPostal.LostFocus += new RoutedEventHandler(tCodigoPostal_LostFocus);
            tCodigoPostal.TextChanged += new TextChangedEventHandler(tCodigoPostal_TextChanged);
            tLada.TextChanged += new TextChangedEventHandler(tLada_TextChanged);
            cColoniaDistrito.SelectionChanged += new SelectionChangedEventHandler(cColoniaDistrito_SelectionChanged);
            cLocalidad.SelectionChanged += new SelectionChangedEventHandler(cLocalidad_SelectionChanged);
            tTelFiscal.TextChanged += new TextChangedEventHandler(tTelFiscal_TextChanged);
            tTelFiscal.LostFocus += new RoutedEventHandler(tTel_LostFocus);


            tbTelExtFiscal.TextChanged += new TextChangedEventHandler(tbTelExtFiscal_TextChanged);
            tbFaxFiscal.TextChanged += new TextChangedEventHandler(tbFaxFiscal_TextChanged);
            tbFaxExtFiscal.TextChanged += new TextChangedEventHandler(tbFaxExtFiscal_TextChanged);


            tbTelExtFiscal.LostFocus += new RoutedEventHandler(tbTelExt_LostFocus);
            tbFaxFiscal.LostFocus += new RoutedEventHandler(tbFax_LostFocus);
            tbFaxExtFiscal.LostFocus += new RoutedEventHandler(tbFaxExt_LostFocus);
            #endregion

            #region Controles de la sección Dirección de Entrega
            tCalleEntrega = (TextBox)frameworkElementns.FindName("tbCalleEntrega");
            tCalleEntrega.MaxLength = (System.Convert.ToInt32(((DataTable)TableLength.GetData("CMD_SOLICITUD_DIRENTREGA", "CALLE")).Rows[0]["LARGO"].ToString()));
            tCalleEntrega.LostFocus +=new RoutedEventHandler(tCalleEntrega_LostFocus);
            tNoExtEntrega = (TextBox)frameworkElementns.FindName("tbNoExtEntrega");
            tNoExtEntrega.MaxLength = (System.Convert.ToInt32(((DataTable)TableLength.GetData("CMD_SOLICITUD_DIRENTREGA", "NUMERO_EXTERIOR")).Rows[0]["LARGO"].ToString()));
            tNoExtEntrega.LostFocus +=new RoutedEventHandler(tNoExtEntrega_LostFocus);
            tNoInEntrega = (TextBox)frameworkElementns.FindName("tbNoIntEntrega");
            tNoInEntrega.MaxLength = (System.Convert.ToInt32(((DataTable)TableLength.GetData("CMD_SOLICITUD_DIRENTREGA", "NUMERO_INTERIOR")).Rows[0]["LARGO"].ToString()));
            tNoInEntrega.LostFocus+=new RoutedEventHandler(tNoInEntrega_LostFocus);
            tCoPoEntrega = (TextBox)frameworkElementns.FindName("tbCopoEntrega");
            cLocalidadEnt = (ComboBox)frameworkElementns.FindName("cbLocalidadEnt");
            tCoPoEntrega.LostFocus += new RoutedEventHandler(tCoPoEntrega_LostFocus);
            tDelMunEnt = (TextBox)frameworkElementns.FindName("tbDelMunEnt");
            cColDisEntrega = (ComboBox)frameworkElementns.FindName("cbColDisEntrega");
            tEdoEntrega = (TextBox)frameworkElementns.FindName("tbEdoEntrega");
           // tEdoEntrega.TextChanged += new TextChangedEventHandler(tEdoEntrega_TextChanged);
            tLadaEntrega = (TextBox)frameworkElementns.FindName("tbLadaEntrega");
            tLadaEntrega.MaxLength = (System.Convert.ToInt32(((DataTable)TableLength.GetData("CMD_SOLICITUD_DIRENTREGA", "LADA")).Rows[0]["LARGO"].ToString()));
            tLadaEntrega.LostFocus +=new RoutedEventHandler(tLadaEntrega_LostFocus);
            tTelEnt = (TextBox)frameworkElementns.FindName("tbTelEnt");
            tTelEnt.LostFocus+=new RoutedEventHandler(tTel_LostFocus);
            tTelEnt.MaxLength = (System.Convert.ToInt32(((DataTable)TableLength.GetData("CMD_SOLICITUD_DIRENTREGA", "TELEFONO")).Rows[0]["LARGO"].ToString()));
            tEdoEntrega.IsEnabled = false;
            tDelMunEnt.IsEnabled = false;


            tbTelExtEntrega = (TextBox)frameworkElementns.FindName("tbTelExtEntrega");
            tbFaxEnt = (TextBox)frameworkElementns.FindName("tbFaxEnt");
            tbFaxExtEntrega = (TextBox)frameworkElementns.FindName("tbFaxExtEntrega");

            tbFaxEnt = (TextBox)frameworkElementns.FindName("tbFaxEnt");
            tbFaxEnt.MaxLength = (System.Convert.ToInt32(((DataTable)TableLength.GetData("CMD_SOLICITUD_DIRENTREGA", "FAX_NUMBER")).Rows[0]["LARGO"].ToString()));
            tbFaxExtEntrega = (TextBox)frameworkElementns.FindName("tbFaxExtEntrega");
            tbFaxExtEntrega.MaxLength = (System.Convert.ToInt32(((DataTable)TableLength.GetData("CMD_SOLICITUD_DIRENTREGA", "FAX_EXTENS")).Rows[0]["LARGO"].ToString()));
            tbTelExtEntrega = (TextBox)frameworkElementns.FindName("tbTelExtEntrega");
            tbTelExtEntrega.MaxLength = (System.Convert.ToInt32(((DataTable)TableLength.GetData("CMD_SOLICITUD_DIRENTREGA", "TEL_EXTENS")).Rows[0]["LARGO"].ToString()));

            tbTelExtFiscal = (TextBox)frameworkElementns.FindName("tbTelExtFiscal");
            tbTelExtFiscal.MaxLength = (System.Convert.ToInt32(((DataTable)TableLength.GetData("CMD_SOLICITUD_DIRFISCAL", "TEL_EXTENS")).Rows[0]["LARGO"].ToString()));
            tbFaxExtFiscal = (TextBox)frameworkElementns.FindName("tbFaxExtFiscal");
            tbFaxExtFiscal.MaxLength = (System.Convert.ToInt32(((DataTable)TableLength.GetData("CMD_SOLICITUD_DIRFISCAL", "FAX_EXTENS")).Rows[0]["LARGO"].ToString()));
            tbFaxFiscal = (TextBox)frameworkElementns.FindName("tbFaxFiscal");
            tbFaxFiscal.MaxLength = (System.Convert.ToInt32(((DataTable)TableLength.GetData("CMD_SOLICITUD_DIRFISCAL", "FAX_NUMBER")).Rows[0]["LARGO"].ToString()));


            tbTelExtEntrega.LostFocus += new RoutedEventHandler(tbTelExt_LostFocus);
            tbFaxEnt.LostFocus += new RoutedEventHandler(tbFax_LostFocus);
            tbFaxExtEntrega.LostFocus += new RoutedEventHandler(tbFaxExt_LostFocus);
            //tbTelExtEntrega.LostFocus

            #endregion

            #region Controles de la sección Responsable Fuerza de Ventas
            cTerritorio = (ComboBox)frameworkElementns.FindName("cbTerritorio");
            cLeadTime = (ComboBox)frameworkElementns.FindName("cbLeadTime");
            tSubdir = (TextBox)frameworkElementns.FindName("tbSubdir");
            tGerencia = (TextBox)frameworkElementns.FindName("tbGerencia");
            cCenLog = (ComboBox)frameworkElementns.FindName("cbCenLog");
            tNoClo = (TextBox)frameworkElementns.FindName("tbNoClo");
            cTerritorio.SelectionChanged += new SelectionChangedEventHandler(cTerritorio_SelectionChanged);
            cCenLog.SelectionChanged += new SelectionChangedEventHandler(cCenLog_SelectionChanged);
            cLeadTime.SelectionChanged += new SelectionChangedEventHandler(cLeadTime_SelectionChanged);
            #endregion

            #region Controles Datos Perfil de Ventas
            tNomDPV = (TextBox)frameworkElementns.FindName("tbNomDPV");
            tNomDPV.LostFocus +=new RoutedEventHandler(tNomDPV_LostFocus);
            tTelDPV = (TextBox)frameworkElementns.FindName("tbTelDPV");
            tTelDPV.LostFocus += new RoutedEventHandler(tTel_LostFocus);
            tTelDPV.MaxLength = (System.Convert.ToInt32(((DataTable)TableLength.GetData("CMD_SOLICITUD_DPV", "TELEFONO")).Rows[0]["LARGO"].ToString()));
            tTitulo = (TextBox)frameworkElementns.FindName("tbTitulo");
            tTitulo.LostFocus +=new RoutedEventHandler(tTitulo_LostFocus);
            tMailDPV = (TextBox)frameworkElementns.FindName("tbMailDPV");
            tMailDPV.MaxLength = (System.Convert.ToInt32(((DataTable)TableLength.GetData("CMD_SOLICITUD_DPV", "CORREO")).Rows[0]["LARGO"].ToString()));
            cZona = (ComboBox)frameworkElementns.FindName("cbZona");
            brdr_diasCol = (Border)frameworkElementns.FindName("brdr_diasCol");
            cZona.SelectionChanged+=new SelectionChangedEventHandler(cZona_SelectionChanged);
            tIVA = (TextBox)frameworkElementns.FindName("tbIVA");
            cMedioColoca = (ComboBox)frameworkElementns.FindName("cbMedioColoca");
            lbl_GrupoPrecios = (Label)frameworkElementns.FindName("lblGrupoPrecios");
            cFrecuencia = (ComboBox)frameworkElementns.FindName("cbFrecuencia");
            chDiaCL = (CheckBox)frameworkElementns.FindName("chbDiaC1");
            chDiaCM = (CheckBox)frameworkElementns.FindName("chbDiaC2");
            chDiaCMi = (CheckBox)frameworkElementns.FindName("chbDiaC3");
            chDiaCJ = (CheckBox)frameworkElementns.FindName("chbDiaC4");
            chDiaCV = (CheckBox)frameworkElementns.FindName("chbDiaC5");
            chDiaCS = (CheckBox)frameworkElementns.FindName("chbDiaC6");

            chDiaEL = (CheckBox)frameworkElementns.FindName("chbDiaE1");
            chDiaEM = (CheckBox)frameworkElementns.FindName("chbDiaE2");
            chDiaEMi = (CheckBox)frameworkElementns.FindName("chbDiaE3");
            chDiaEJ = (CheckBox)frameworkElementns.FindName("chbDiaE4");
            chDiaEV = (CheckBox)frameworkElementns.FindName("chbDiaE5");
            chDiaES = (CheckBox)frameworkElementns.FindName("chbDiaE6");

            chDiaCL.Checked += new RoutedEventHandler(chDiaC_Click);
            chDiaCM.Checked += new RoutedEventHandler(chDiaC_Click);
            chDiaCMi.Checked += new RoutedEventHandler(chDiaC_Click);
            chDiaCJ.Checked += new RoutedEventHandler(chDiaC_Click);
            chDiaCV.Checked += new RoutedEventHandler(chDiaC_Click);
            chDiaCS.Checked += new RoutedEventHandler(chDiaC_Click);

            chDiaCL.Unchecked += new RoutedEventHandler(chDiaC_Click);
            chDiaCM.Unchecked += new RoutedEventHandler(chDiaC_Click);
            chDiaCMi.Unchecked += new RoutedEventHandler(chDiaC_Click);
            chDiaCJ.Unchecked += new RoutedEventHandler(chDiaC_Click);
            chDiaCV.Unchecked += new RoutedEventHandler(chDiaC_Click);
            chDiaCS.Unchecked += new RoutedEventHandler(chDiaC_Click);

            tMailDPV.LostFocus += new RoutedEventHandler(Email_LostFocus);

            #endregion

            #region Controles de la sección Información Adicional
            tRespoFV = (TextBox)frameworkElementns.FindName("tbRFV");
            tNoEmpleado = (TextBox)frameworkElementns.FindName("tbNoEmpleado");

            #endregion

            #region Controles de la sección Datos Bancarios
            cClaveBanco = (ComboBox)frameworkElementns.FindName("cbClaveBanco");
            cClaveBanco.SelectionChanged += new SelectionChangedEventHandler(cClaveBanco_SelectionChanged);

            lbNomBanco = (Label)frameworkElementns.FindName("lblNomBanco");
            tCuentaBancaria = (TextBox)frameworkElementns.FindName("tbCuentaBancaria");
            tCuentaBancaria.MaxLength = (System.Convert.ToInt32(((DataTable)TableLength.GetData("CMD_SOLICITUD_DATOSBANC", "CTA_BANCARIA")).Rows[0]["LARGO"].ToString()));
            tCuentaBancaria.LostFocus +=new RoutedEventHandler(tCuentaBancaria_LostFocus);
            tSucursal = (TextBox)frameworkElementns.FindName("tbSucursal");
            tSucursal.MaxLength = (System.Convert.ToInt32(((DataTable)TableLength.GetData("CMD_SOLICITUD_DATOSBANC", "SUCURSAL")).Rows[0]["LARGO"].ToString()));
            tSucursal.LostFocus +=new RoutedEventHandler(tSucursal_LostFocus);
            #endregion
            #endregion


            #region Carga de Combobox con Stored Procedure
            DataTable dt = TipoSolicitante.GetData();

            chMismoDom.Click -= new RoutedEventHandler(chMismoDom_Click);
            cPersona.SelectionChanged -= new SelectionChangedEventHandler(cPersona_SelectionChanged);
            cTipoSolicitud.SelectionChanged -= new SelectionChangedEventHandler(cTipoSolicitud_SelectionChanged);

            cargarcombos(cTipoSolicitud, dt,"DSC_TIPO_SOLICITANTE", "UNID_TIPO_SOLICITANTE" );

            dt = TipoPersonaFisica.GetData();
            cargarcombos(cPersona, dt, "DSC_TIPO_PERSONA_FISCAL","ID_TIPO_PERSONA_FISCAL");

            dt = TipoNegocio.GetData();
            cargarcombos(cTipoNegocios, dt,"DSC_TIPO_NEGOCIO", "ID_TIPO_NEGOCIO");
            
            dt = LeadTime.GetData();
            cargarcombos(cLeadTime, dt, "TRANSPORTE","ID_LEADTIME");

            dt = MedioColocacion.GetData();
            cargarcombos(cMedioColoca, dt, "DSC_MED_COLOCACION", "ID_MED_COLOCACION");

            dt = Frecuencia.GetData();
            cargarcombos(cFrecuencia, dt, "DSC_FRECUENCIA", "ID_FRECUENCIA");

            dt = Banco.GetData();
            cargarcombos(cClaveBanco, dt, "ID_BANCO", "ID_BANCO");

            dt = Clo.GetData();
            cargarcombos(cCenLog, dt, "DSCyVENTA", "ID_CLO");
            if (dt.Rows.Count != 0) cCenLog.SelectedIndex = 0; else cCenLog.SelectedIndex = -1;

            dt = Clientes4.GetData();
            cargarcombos(cGrupoClientes4, dt, "DSC_GRUPOCLIENTES4", "ID_GRUPOCLIENTES4");

            cClaveBanco_SelectionChanged(null, null);

            //SECCION RESPONSABLE FUERZA DE VENTAS
            ObtieneRespVentas fvtas = new ObtieneRespVentas();
            dt = Estructura.GetData(5, fvtas.IdTerritorio);

            cargarcombos(cTerritorio, dt, "DSC_ESTRUCTURA", "ID_CODIGO");

            cTerritorio_SelectionChanged(null, null);

            //SECCION INFORMACION ADICIONAL

            tRespoFV.Text = fvtas.Nombre;
            tNoEmpleado.Text = fvtas.HRCode;
            cTerritorio_SelectionChanged(null, null);
            #endregion

          

            #region Carga del Panel de Navegación después de accionar ALTA
            string nombre2 = @"SeccionesReemplazo.xaml";

            DependencyObject rootElement2;
            using (FileStream fs2 = new FileStream(nombre2, FileMode.Open))
            {
                rootElement2 = (DependencyObject)XamlReader.Load(fs2);
            }

            PanelNavegacion.Content= rootElement2;
            FrameworkElement frameworkElement2 = (FrameworkElement)rootElement2;
            ArrayList al = SolAlta.UISolAlta.GetSecRangesReemp();
            #endregion


            #region Pegar eventos a los botones de navegacion

            //Pegar eventos a los botones de navegacion
            Grid grdNav01 = (Grid)frameworkElement2.FindName("grdNavSolicitudReemplazo");
            foreach (Object tmp in grdNav01.Children)
            {
                if (tmp is Border)
                {
                    Border tmpBrd = (Border)tmp;
                    //Point relativePoint = new Point();
                    tmpBrd.MouseUp += delegate(object sender3, MouseButtonEventArgs e3)
                    {
                        double tgt = 0;
                        Grid _brdNavgrdNav01 = (Grid)frameworkElement2.FindName("grdNavSolicitudReemplazo");
                        foreach (Object __tmp in _brdNavgrdNav01.Children)
                        {
                            if (__tmp is Border)
                            {
                                Border __tmpBrd = (Border)__tmp;
                                __tmpBrd.Background = Brushes.Transparent;
                            }
                        }

                        foreach (SolAlta.NavSecRange ns in al)
                        {
                            if (ns.controlName == ((Border)sender3).Name)
                            {
                                tgt = ns.SEC_INI;
                            }
                        }

                        ((Border)sender3).Background = Brushes.White;
                        PanelCentral.ScrollToVerticalOffset(tgt);
                    };
                }
            }

            #endregion

            #region efecto scroll
            //Function para cambiar automaticamente de etiqueta cuando se hace scroll
            this.PanelCentral.ScrollChanged += delegate(object sender2, ScrollChangedEventArgs e2)
            {
                foreach (SolAlta.NavSecRange ns in al)
                {
                    if (e2.VerticalOffset >= ns.SEC_INI && e2.VerticalOffset <= ns.SEC_END)
                    {
                        Grid grdNav = (Grid)frameworkElement2.FindName("grdNavSolicitudReemplazo");
                        foreach (Object tmp in grdNav.Children)
                        {
                            if (tmp is Border)
                            {
                                Border tmpBrd = (Border)tmp;
                                var converter = new System.Windows.Media.BrushConverter();
                                tmpBrd.Background = Brushes.Transparent;

                                Border sel = (Border)frameworkElement2.FindName(ns.controlName);
                                sel.Background = Brushes.White;
                            }
                        }
                    }
                }
            };

            #endregion

            cTipoNegocios.SelectionChanged += new SelectionChangedEventHandler(cTipoNegocios_SelectionChanged);

            targetPath = System.Configuration.ConfigurationManager.AppSettings["ClientDocsFolder"];
            primerArchivo = "-1";
            sSolicitudDocs = "-1";
            cperso = cPersona.SelectedValue.ToString();
            ctiposol = cTipoSolicitud.SelectedValue.ToString();
            targetPath = AppConfs.ClientDocsFolder;
            if (chMismoDom.IsChecked == true)
                check = 1;
            else 
                check = 0;

            setLengthRFC();
            //ft = 0;
            PanelCentral.ScrollToVerticalOffset(0);
        }

        void txt_numeroCliente_LostFocus(object sender, RoutedEventArgs e)
        {
            if (((TextBox)sender).Text != "")
                setTbToBlank(sender);
        }

        void txt_nombreCliente_LostFocus(object sender, RoutedEventArgs e)
        {
            if (((TextBox)sender).Text != "")
                setTbToBlank(sender);
        }

        public override Solicitud GetDatatoSave(object sender)
        {
            if (sol.Unid_solicitud != 0)
                lbl_unidSol.Content = sol.Unid_solicitud.ToString();
            if (sol.Unid_docinfo != 0)
                lbl_unidDocinfo.Content = sol.Unid_docinfo.ToString();
            if (sol.Unid_datos != 0)
                lbl_unidDatos.Content = sol.Unid_datos.ToString();
            if (sol.Unid_datosgral != 0)
                lbl_unidDatgral.Content = sol.Unid_datosgral.ToString();
            if (sol.Unid_dirfiscal != 0)
                lbl_unidDirFiscal.Content = sol.Unid_dirfiscal.ToString();
            if (sol.Unid_direntrega != 0)
                lbl_unidDirEntrega.Content = sol.Unid_direntrega.ToString();
            if (sol.Unid_rfv != 0)
                lbl_unidRFV.Content = sol.Unid_rfv.ToString();
            if (sol.Unid_dpv != 0)
                lbl_unidDPV.Content = sol.Unid_dpv.ToString();
            if (sol.Unid_infoad != 0)
                lbl_unidInfoad.Content = sol.Unid_infoad.ToString();
            if (sol.Unid_datosbanc != 0)
                lbl_unidBanc.Content = sol.Unid_datosbanc.ToString();
            if (sol.Unid_documentos != 0)
                lbl_unidDocumentos.Content = sol.Unid_documentos.ToString();
            if (sol.Id_status != 0)
                lbl_idStatus.Content = sol.Id_status.ToString();
            if (sol.Id_prioridad != 0)
                lbl_idPrioridad.Content = sol.Id_prioridad.ToString();
            if (sol.Id_tipo != 0)
                lbl_idTipo.Content = sol.Id_tipo.ToString();

            sol.parametros.Clear();

            #region parametros
            //Solicitud sol = new Solicitud();
            // ----------   DOCINFO
            sol.SetDictionaryParameterValues("docInfo_unidDocInfo", lbl_unidDocinfo.Content.ToString());
            // ----------   STATUS, PRIORIDAD Y TIPO
            sol.SetDictionaryParameterValues("sol_idTipoSol", lbl_idTipo.Content.ToString()); //alta
            sol.SetDictionaryParameterValues("sol_idPrio", lbl_idPrioridad.Content.ToString());
            sol.SetDictionaryParameterValues("sol_idSolStat", lbl_idStatus.Content.ToString()); //borrador
            if (sender.GetType() == typeof(System.Windows.Controls.Image))
                if (((Image)sender).Name == "img_Enviar")
                    sol.SetDictionaryParameterValues("sol_unid_rol", AppConfs.Unid_datosMaestros.ToString());
            //----------- DOCUMENTOS
            if (SolicitudDocs.Trim() != "-1" && SolicitudDocs.Trim() != "0")
                sol.SetDictionaryParameterValues("doctos_unidDoctos", SolicitudDocs);

            foreach (var child in spAlta.Children)
            {
                if (child.GetType() == typeof(System.Windows.Controls.Grid))
                {
                    Grid chldGrid = (Grid)child;
                    switch (chldGrid.Name)
                    {
                        case "DatosCliente":
                            sol.SetDictionaryParameterValues("sol_numCte", txt_numeroCliente.Text);
                            sol.SetDictionaryParameterValues("sol_nomCte", txt_nombreCliente.Text);
                            break;
                        case "mainGrid":
                            sol.SetDictionaryParameterValues("unidSolicitud", lbl_unidSol.Content.ToString());
                            sol.SetDictionaryParameterValues("datsol_unidSolicitudDatos", lbl_unidDatos.Content.ToString());

                            sol.SetDictionaryParameterValues("datsol_unidTipoSolicitante", cTipoSolicitud.SelectedValue.ToString());
                            sol.SetDictionaryParameterValues("datsol_isMismoDomicilio", Convert.ToInt32(chMismoDom.IsChecked).ToString());
                            sol.SetDictionaryParameterValues("datsol_isProveedor", Convert.ToInt32(chProveedor.IsChecked).ToString());
                            sol.SetDictionaryParameterValues("datsol_isOtrasCategorias", Convert.ToInt32(chOtrasCateg.IsChecked).ToString());
                            sol.SetDictionaryParameterValues("datsol_isOtrosClientes", Convert.ToInt32(chOtrosClientes.IsChecked).ToString());
                            sol.SetDictionaryParameterValues("datsol_idTipoPersonaFiscal", cPersona.SelectedValue.ToString());

                            break;
                        case "gdDatosGenerales":
                            sol.SetDictionaryParameterValues("datgral_unidSolicitud", lbl_unidDatgral.Content.ToString());
                            sol.SetDictionaryParameterValues("datgral_idTipoNeg", cTipoNegocios.SelectedValue.ToString());
                            sol.SetDictionaryParameterValues("datgral_razonSocial", tRazonSocial.Text);
                            sol.SetDictionaryParameterValues("datgral_rfc", tRFC.Text);
                            sol.SetDictionaryParameterValues("datgral_correo", tEmail.Text);
                            sol.SetDictionaryParameterValues("datgral_nombreSucursal", tNombreSucursal.Text);
                            sol.SetDictionaryParameterValues("datgral_numSucursal", tNumeroSucursal.Text);
                            sol.SetDictionaryParameterValues("datgral_idGrupoClientes4", cGrupoClientes4.SelectedValue.ToString());

                            break;
                        case "gdDatosFiscales":
                            sol.SetDictionaryParameterValues("dirFis_unidDirFiscal", lbl_unidDirFiscal.Content.ToString());
                            sol.SetDictionaryParameterValues("dirFis_calle", tCalle.Text);
                            sol.SetDictionaryParameterValues("dirFis_numExt", tNoExterior.Text);
                            sol.SetDictionaryParameterValues("dirFis_numInt", tNoInterior.Text);
                            if (UnidDirFiscal != "")
                                sol.SetDictionaryParameterValues("dirFis_unidSepomex", UnidDirFiscal);//tCodigoPostal.Text.ToString());
                            sol.SetDictionaryParameterValues("dirFis_lada", tLada.Text);
                            sol.SetDictionaryParameterValues("dirFis_tel", tTelFiscal.Text);
                            sol.SetDictionaryParameterValues("dirFis_local", (cLocalidad.DataContext != null) ? cLocalidad.SelectedValue.ToString() : "");
                            sol.SetDictionaryParameterValues("dirFis_TelExtFiscal", tbTelExtFiscal.Text);
                            sol.SetDictionaryParameterValues("dirFis_FaxFiscal", tbFaxFiscal.Text);
                            sol.SetDictionaryParameterValues("dirFis_FaxExtFiscal", tbFaxExtFiscal.Text);

                            break;
                        case "gdDirEntrega":
                            sol.SetDictionaryParameterValues("dirEnt_unidDirEntrega", lbl_unidDirEntrega.Content.ToString());
                            sol.SetDictionaryParameterValues("dirEnt_calle", tCalleEntrega.Text);
                            sol.SetDictionaryParameterValues("dirEnt_numExt", tNoExtEntrega.Text);
                            sol.SetDictionaryParameterValues("dirEnt_numInt", tNoInEntrega.Text);
                            if (UnidDirEntrega != "")
                                sol.SetDictionaryParameterValues("dirEnt_unidSepomex", UnidDirEntrega);//tCoPoEntrega.Text.ToString());
                            sol.SetDictionaryParameterValues("dirEnt_lada", tLadaEntrega.Text);
                            sol.SetDictionaryParameterValues("dirEnt_tel", tTelEnt.Text);
                            sol.SetDictionaryParameterValues("dirEnt_local", (cLocalidadEnt.DataContext != null) ? cLocalidadEnt.SelectedValue.ToString() : "");
                            sol.SetDictionaryParameterValues("dirEnt_TelExtEntrega", tbTelExtEntrega.Text);
                            sol.SetDictionaryParameterValues("dirEnt_FaxEnt", tbFaxEnt.Text);
                            sol.SetDictionaryParameterValues("dirEnt_FaxExtEntrega", tbFaxExtEntrega.Text);

                            break;
                        case "gdRFV":
                            sol.SetDictionaryParameterValues("datRFV_unidRFV", lbl_unidRFV.Content.ToString());
                            sol.SetDictionaryParameterValues("datRFV_ter", cTerritorio.SelectedValue.ToString());
                            sol.SetDictionaryParameterValues("datRFV_idLeadTime", cLeadTime.SelectedValue.ToString());
                            sol.SetDictionaryParameterValues("datRFV_subdir", tSubdir.Text.ToString());
                            sol.SetDictionaryParameterValues("datRFV_geren", tGerencia.Text);
                            sol.SetDictionaryParameterValues("datRFV_idClo", cCenLog.SelectedValue.ToString());

                            break;
                        case "gdDatosPV":
                            string diasCol = "";
                            string diasEnt = "";
                            foreach (var item in chldGrid.Children)
                            {
                                if (item.GetType() == typeof(System.Windows.Controls.CheckBox))
                                {
                                    CheckBox chbx = (CheckBox)item;
                                    if (chbx.Name.Contains("chbDiaC"))
                                    {
                                        if (chbx.IsChecked.Value)
                                        {
                                            if (diasCol == "") diasCol = "1";
                                            else diasCol = diasCol + ",1";
                                        }
                                        else
                                        {
                                            if (diasCol == "") diasCol = "0";
                                            else diasCol = diasCol + ",0";
                                        }
                                    }
                                    else if (chbx.Name.Contains("chbDiaE"))
                                    {
                                        if (chbx.IsChecked.Value)
                                        {
                                            if (diasEnt == "") diasEnt = "1";
                                            else diasEnt = diasEnt + ",1";
                                        }
                                        else
                                        {
                                            if (diasEnt == "") diasEnt = "0";
                                            else diasEnt = diasEnt + ",0";
                                        }
                                    }//if-else
                                }//if
                            }//foreach

                            sol.SetDictionaryParameterValues("datDPV_unidDPV", lbl_unidDPV.Content.ToString());
                            sol.SetDictionaryParameterValues("datDPV_nom", tNomDPV.Text);
                            sol.SetDictionaryParameterValues("datDPV_tel", tTelDPV.Text);
                            sol.SetDictionaryParameterValues("datDPV_titulo", tTitulo.Text);
                            sol.SetDictionaryParameterValues("datDPV_correo", tMailDPV.Text);
                            sol.SetDictionaryParameterValues("datDPV_idZona", cZona.SelectedValue.ToString());
                            sol.SetDictionaryParameterValues("datDPV_diasCol", diasCol);
                            sol.SetDictionaryParameterValues("datDPV_diasEnt", diasEnt);
                            sol.SetDictionaryParameterValues("datDPV_idMedCol", cMedioColoca.SelectedValue.ToString());
                            sol.SetDictionaryParameterValues("datDPV_idFrec", cFrecuencia.SelectedValue.ToString());
                            sol.SetDictionaryParameterValues("datDPV_grupoPrecio", lbl_GrupoPrecios.Content.ToString());
                            sol.SetDictionaryParameterValues("datDPV_idIva", tIVA.Text);
                            //TODO: bind medios de colocación, frecuencia, gpo de precios

                            break;
                        case "gdInfoAd":
                            sol.SetDictionaryParameterValues("infoad_unidInfoad", lbl_unidInfoad.Content.ToString());
                            sol.SetDictionaryParameterValues("infoad_respoFDV", tRespoFV.Text);
                            sol.SetDictionaryParameterValues("infoad_numEmpleado", tNoEmpleado.Text);

                            break;
                        case "gdDatosBanc":
                            sol.SetDictionaryParameterValues("datBnc_unidBanc", lbl_unidBanc.Content.ToString());
                            sol.SetDictionaryParameterValues("datBnc_idBanc", cClaveBanco.SelectedValue.ToString());
                            sol.SetDictionaryParameterValues("datBnc_ctaBanc", tCuentaBancaria.Text);
                            sol.SetDictionaryParameterValues("datBnc_suc", tSucursal.Text);

                            break;
                        default:
                            break;
                    }//end switch
                }//if
            }//foreach

            #endregion
            //pop.HidePopup();
            return sol;
        }


        void tbFaxExtFiscal_TextChanged(object sender, TextChangedEventArgs e)
        {
            if (chMismoDom.IsChecked == true)
            {
                tbFaxExtEntrega.Text = tbFaxExtFiscal.Text;
            }
        }

        void tbFaxFiscal_TextChanged(object sender, TextChangedEventArgs e)
        {
            if (chMismoDom.IsChecked == true)
            {
                tbFaxEnt.Text = tbFaxFiscal.Text;
            }
        }

        void tbTelExtFiscal_TextChanged(object sender, TextChangedEventArgs e)
        {
            if (chMismoDom.IsChecked == true)
            {
                tbTelExtEntrega.Text = tbTelExtFiscal.Text;

            }
        }

        override public void cargaListTextBox()
        {
            try
            {
                this.liTxt.Add(txt_nombreCliente);
                this.liTxt.Add(txt_numeroCliente);
                //Datos Generales
                this.liTxt.Add(tRazonSocial);
                this.liTxt.Add(tRFC);
                this.liTxt.Add(tEmail);
                this.liTxt.Add(tNombreSucursal);
                this.liTxt.Add(tNumeroSucursal);

                //Direccion Fiscal
                this.liTxt.Add(tCalle);
                this.liTxt.Add(tNoExterior);
                this.liTxt.Add(tNoInterior);
                this.liTxt.Add(tbFaxFiscal);
                this.liTxt.Add(tbFaxExtFiscal);
                this.liTxt.Add(tbTelExtFiscal);
                //this.liTxt.Add(tEstado);
                //this.liTxt.Add(tDelMunicipio);
                this.liTxt.Add(tLada);
                this.liTxt.Add(tTelFiscal);

                //Direccion Entrega
                this.liTxt.Add(tCalleEntrega);
                this.liTxt.Add(tNoExtEntrega);
                this.liTxt.Add(tNoInEntrega);
                this.liTxt.Add(tbTelExtEntrega);
                this.liTxt.Add(tbFaxExtEntrega);
                this.liTxt.Add(tbFaxEnt);
                //this.liTxt.Add(tEdoEntrega);
                //this.liTxt.Add(tDelMunEnt);
                this.liTxt.Add(tLadaEntrega);
                this.liTxt.Add(tTelEnt);

                //Responsable Fuerza de Ventas
                this.liTxt.Add(tGerencia);
                this.liTxt.Add(tNoClo);

                //Datos Perfil de Ventas
                this.liTxt.Add(tNomDPV);
                this.liTxt.Add(tTelDPV);
                this.liTxt.Add(tTitulo);
                this.liTxt.Add(tMailDPV);
                this.liTxt.Add(tIVA);

                //info Adicional
                this.liTxt.Add(tRespoFV);
                this.liTxt.Add(tNoEmpleado);

                //Datos Bancarios
                this.liTxt.Add(tCuentaBancaria);
                this.liTxt.Add(tSucursal);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        
    }
    
}
